package Telas;

import Conexao.ConectaBD;
import java.awt.Toolkit;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import net.proteanit.sql.DbUtils;

public class Tela_CadCliente extends javax.swing.JFrame {

    Connection conecta;
    PreparedStatement pst;
    ResultSet rs;

    public Tela_CadCliente() throws ClassNotFoundException {
        initComponents();
        setSize(1283, 653);
        setLocationRelativeTo(null);
        conecta = ConectaBD.conectabd();
        listarClientes();
        Icon();
    }
    
//<----------------------------------------------------------------------------------------------------------------------------------------->    

    private void Icon(){
    
        setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("assistec_icon.png")));
        
    }    
    
//<----------------------------------------------------------------------------------------------------------------------------------------->    

    public void listarClientes() {
        String sql = "Select *from cliente order by id Asc";
        try {
            pst = conecta.prepareStatement(sql);
            rs = pst.executeQuery();
            jt_cliente.setModel(DbUtils.resultSetToTableModel(rs));
        } catch (SQLException error) {
            JOptionPane.showMessageDialog(null, error);
        }
    }
    
//<----------------------------------------------------------------------------------------------------------------------------------------->    

    public void cadastrarClientes() {
        String sql = "Insert into cliente (Nome,Endereço,Numero,Bairro,Cidade,CEP,Estado,Telefone,Email,Data,Complemento,Sexo,RG,CPF,CNPJ) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        
        if(tf_nome.getText().equals("")){
        JOptionPane.showMessageDialog(null, "Campo Nome é Obrigatório", "Aviso", JOptionPane.WARNING_MESSAGE);
        return;
        }
        if(cb_sexo.getSelectedItem().equals("SEXO")){
        JOptionPane.showMessageDialog(null, "Campo Sexo é Obrigatório", "Aviso", JOptionPane.WARNING_MESSAGE);
        return;
        }
        if(jf_data.getText().equals("")){
        JOptionPane.showMessageDialog(null, "Campo Data é Obrigatório", "Aviso", JOptionPane.WARNING_MESSAGE);
        return;
        }
        if(tf_endereco.getText().equals("")){
        JOptionPane.showMessageDialog(null, "Campo Endereço é Obrigatório", "Aviso", JOptionPane.WARNING_MESSAGE);
        return;
        }
        if(tf_numero.getText().equals("")){
        JOptionPane.showMessageDialog(null, "Campo Nº é Obrigatório", "Aviso", JOptionPane.WARNING_MESSAGE);
        return;
        }
        if(tf_cidade.getText().equals("")){
        JOptionPane.showMessageDialog(null, "Campo Cidade é Obrigatório", "Aviso", JOptionPane.WARNING_MESSAGE);
        return;
        }
        if(cb_estado.getSelectedItem().equals("ESTADO")){
        JOptionPane.showMessageDialog(null, "Campo Estado é Obrigatório", "Aviso", JOptionPane.WARNING_MESSAGE);
        return;
        }
        if(jf_telefone.getText().equals("(  )    -    ")){
        JOptionPane.showMessageDialog(null, "Campo Telefone é Obrigatório", "Aviso", JOptionPane.WARNING_MESSAGE);
        return;
        }
        
        try {
            pst = conecta.prepareStatement(sql);
            pst.setString(1, tf_nome.getText());            
            pst.setString(2, tf_endereco.getText());
            pst.setString(3, tf_numero.getText());
            pst.setString(4, tf_bairro.getText());
            pst.setString(5, tf_cidade.getText());
            pst.setString(6, jf_cep.getText());
            pst.setString(7, (String) cb_estado.getSelectedItem());
            pst.setString(8, jf_telefone.getText());
            pst.setString(9, tf_email.getText());
            pst.setString(10, jf_data.getText());
            pst.setString(11, tf_complemento.getText());
            pst.setString(12, (String) cb_sexo.getSelectedItem());
            pst.setString(13, jf_rg.getText());
            pst.setString(14, jf_cpf.getText());
            pst.setString(15, jf_cnpj.getText());

            pst.execute();
            JOptionPane.showMessageDialog(null, "Cadastrado com Sucesso!", "Cadastrado com Sucesso", JOptionPane.INFORMATION_MESSAGE);
            listarClientes();
            Limpar();

        } catch (SQLException error) {
            JOptionPane.showMessageDialog(null, error);
        }
    }
    
//<----------------------------------------------------------------------------------------------------------------------------------------->    

    public void pesquisarClientes() {
        String sql = "Select *from cliente where Nome like ?";

        try {
            pst = conecta.prepareStatement(sql);
            pst.setString(1, tf_pesquisar.getText() + "%");
            rs = pst.executeQuery();
            jt_cliente.setModel(DbUtils.resultSetToTableModel(rs));
        } catch (SQLException error) {
            JOptionPane.showMessageDialog(null, error);
        }
    }
    
//<----------------------------------------------------------------------------------------------------------------------------------------->    

    public void mostraItens() {
        int seleciona = jt_cliente.getSelectedRow();
        tf_id.setText(jt_cliente.getModel().getValueAt(seleciona, 0).toString());
        tf_nome.setText(jt_cliente.getModel().getValueAt(seleciona, 1).toString());
        tf_endereco.setText(jt_cliente.getModel().getValueAt(seleciona, 2).toString());
        tf_numero.setText(jt_cliente.getModel().getValueAt(seleciona, 3).toString());
        tf_bairro.setText(jt_cliente.getModel().getValueAt(seleciona, 4).toString());
        tf_cidade.setText(jt_cliente.getModel().getValueAt(seleciona, 5).toString());
        jf_cep.setText(jt_cliente.getModel().getValueAt(seleciona, 6).toString());
        cb_estado.setSelectedItem(jt_cliente.getModel().getValueAt(seleciona, 7).toString());
        jf_telefone.setText(jt_cliente.getModel().getValueAt(seleciona, 8).toString());
        tf_email.setText(jt_cliente.getModel().getValueAt(seleciona, 9).toString());
        jf_data.setText(jt_cliente.getModel().getValueAt(seleciona, 10).toString());
        tf_complemento.setText(jt_cliente.getModel().getValueAt(seleciona, 11).toString());
        cb_sexo.setSelectedItem(jt_cliente.getModel().getValueAt(seleciona, 12).toString());
        jf_rg.setText(jt_cliente.getModel().getValueAt(seleciona, 13).toString());
        jf_cpf.setText(jt_cliente.getModel().getValueAt(seleciona, 14).toString());
        jf_cnpj.setText(jt_cliente.getModel().getValueAt(seleciona, 15).toString());
    }
    
//<----------------------------------------------------------------------------------------------------------------------------------------->    

    public void editarClientes() {
        String sql = "Update cliente set Nome = ?,Endereço = ?,Numero = ?,Bairro = ?,Cidade = ?,CEP = ?,Estado = ?,Telefone = ?,Email = ?,Data = ?,Complemento = ?,Sexo = ?,RG = ?,CPF = ?,CNPJ = ? where id = ? ";

        try {
            pst = conecta.prepareStatement(sql);
            pst.setString(1, tf_nome.getText());            
            pst.setString(2, tf_endereco.getText());
            pst.setString(3, tf_numero.getText());
            pst.setString(4, tf_bairro.getText());
            pst.setString(5, tf_cidade.getText());
            pst.setString(6, jf_cep.getText());
            pst.setString(7, (String) cb_estado.getSelectedItem());
            pst.setString(8, jf_telefone.getText());
            pst.setString(9, tf_email.getText());
            pst.setString(10, jf_data.getText());
            pst.setString(11, tf_complemento.getText());
            pst.setString(12, (String) cb_sexo.getSelectedItem());
            pst.setString(13, jf_rg.getText());
            pst.setString(14, jf_cpf.getText());
            pst.setString(15, jf_cnpj.getText());
            pst.setInt(16, Integer.parseInt(tf_id.getText()));
            pst.executeUpdate();
            JOptionPane.showMessageDialog(null, "Cliente atualizado com sucesso");
            listarClientes();

        } catch (SQLException error) {
            JOptionPane.showMessageDialog(null, error);
        }
    }
    
//<----------------------------------------------------------------------------------------------------------------------------------------->    

    public void deletarClientes() {
        String sql = "Delete from cliente where id = ?";

        try {
            pst = conecta.prepareStatement(sql);
            pst.setInt(1, Integer.parseInt(tf_id.getText()));
            pst.execute();
            listarClientes();
        } catch (SQLException error) {

            JOptionPane.showMessageDialog(null, error);
        }
    }
    
//<----------------------------------------------------------------------------------------------------------------------------------------->    

        public void Novo(){
        
            try {
                
                tf_nome.setEditable(true);
                jf_data.setEditable(true);
                tf_endereco.setEditable(true);
                tf_numero.setEditable(true);
                tf_complemento.setEditable(true);
                tf_bairro.setEditable(true);
                tf_cidade.setEditable(true);
                jf_cep.setEditable(true);               
                jf_telefone.setEditable(true);
                tf_email.setEditable(true);
                jf_rg.setEditable(true);
                jf_cpf.setEditable(true); 
                jf_cnpj.setEditable(true); 
                cb_estado.setEnabled(true);
                cb_sexo.setEnabled(true);
                jb_salvar.setEnabled(true);
                
                Limpar(); 
                
            } catch (Exception e) {
            }
        }
        
//<----------------------------------------------------------------------------------------------------------------------------------------->    

                public void Limpar(){
                                    
                tf_nome.setText("");
                tf_endereco.setText("");
                tf_numero.setText("");
                tf_bairro.setText("");
                tf_cidade.setText("");
                jf_cep.setText("");
                jf_telefone.setText("");
                tf_email.setText("");
                tf_id.setText("");
                tf_pesquisar.setText("");
                jf_data.setText("");
                tf_complemento.setText("");
                cb_estado.setSelectedItem("ESTADO");
                cb_sexo.setSelectedItem("SEXO");
                jf_rg.setText("");
                jf_cpf.setText("");
                jf_cnpj.setText("");
                
                }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cb_sexo = new javax.swing.JComboBox();
        jLabel19 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        tf_complemento = new javax.swing.JTextField();
        jf_telefone = new javax.swing.JFormattedTextField();
        cb_estado = new javax.swing.JComboBox();
        jf_data = new javax.swing.JFormattedTextField();
        jLabel17 = new javax.swing.JLabel();
        jb_salvar = new javax.swing.JButton();
        jb_editar = new javax.swing.JButton();
        jb_excluir = new javax.swing.JButton();
        jLabel16 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jt_cliente = new javax.swing.JTable();
        jLabel15 = new javax.swing.JLabel();
        tf_pesquisar = new javax.swing.JTextField();
        tf_id = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel12 = new javax.swing.JLabel();
        tf_numero = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jb_fechar = new javax.swing.JButton();
        jb_limpar = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jf_cep = new javax.swing.JFormattedTextField();
        jLabel9 = new javax.swing.JLabel();
        tf_email = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        tf_cidade = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        tf_bairro = new javax.swing.JTextField();
        tf_endereco = new javax.swing.JTextField();
        tf_nome = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jf_rg = new javax.swing.JFormattedTextField();
        jf_cpf = new javax.swing.JFormattedTextField();
        jf_cnpj = new javax.swing.JFormattedTextField();
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jLabel23 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("AssisTec - Cadastrar Cliente");
        setResizable(false);
        getContentPane().setLayout(null);

        cb_sexo.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        cb_sexo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SEXO", "FEMININO", "MASCULINO" }));
        cb_sexo.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        cb_sexo.setEnabled(false);
        getContentPane().add(cb_sexo);
        cb_sexo.setBounds(320, 30, 120, 30);

        jLabel19.setBackground(new java.awt.Color(255, 255, 255));
        jLabel19.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel19.setForeground(new java.awt.Color(255, 255, 255));
        jLabel19.setText("SEXO");
        getContentPane().add(jLabel19);
        jLabel19.setBounds(320, 10, 33, 14);

        jLabel18.setBackground(new java.awt.Color(255, 255, 255));
        jLabel18.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel18.setForeground(new java.awt.Color(255, 255, 255));
        jLabel18.setText("COMPLEMENTO");
        getContentPane().add(jLabel18);
        jLabel18.setBounds(90, 70, 120, 14);

        tf_complemento.setEditable(false);
        tf_complemento.setBackground(new java.awt.Color(255, 255, 255));
        tf_complemento.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        tf_complemento.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        tf_complemento.setSelectionColor(new java.awt.Color(0, 0, 0));
        getContentPane().add(tf_complemento);
        tf_complemento.setBounds(90, 90, 160, 30);

        jf_telefone.setEditable(false);
        jf_telefone.setBackground(new java.awt.Color(255, 255, 255));
        jf_telefone.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        try {
            jf_telefone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jf_telefone.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jf_telefone.setSelectionColor(new java.awt.Color(0, 0, 0));
        getContentPane().add(jf_telefone);
        jf_telefone.setBounds(210, 150, 110, 30);

        cb_estado.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        cb_estado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESTADO", "Acre - AC", "Alagoas - AL", "Amapá - AP", "Amazonas - AM", "Bahia  - BA", "Ceará - CE", "Distrito Federal  - DF", "Espírito Santo - ES", "Goiás - GO", "Maranhão - MA", "Mato Grosso - MT", "Mato Grosso do Sul - MS", "Minas Gerais - MG", "Pará - PA", "Paraíba - PB", "Paraná - PR", "Pernambuco - PE", "Piauí - PI", "Rio de Janeiro - RJ", "Rio Grande do Norte - RN", "Rio Grande do Sul - RS", "Rondônia - RO", "Roraima - RR", "Santa Catarina - SC", "São Paulo - SP", "Sergipe - SE", "Tocantins - TO" }));
        cb_estado.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        cb_estado.setEnabled(false);
        getContentPane().add(cb_estado);
        cb_estado.setBounds(10, 150, 190, 30);

        jf_data.setEditable(false);
        jf_data.setBackground(new java.awt.Color(255, 255, 255));
        jf_data.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        try {
            jf_data.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jf_data.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jf_data.setSelectionColor(new java.awt.Color(0, 0, 0));
        getContentPane().add(jf_data);
        jf_data.setBounds(450, 30, 90, 30);

        jLabel17.setBackground(new java.awt.Color(255, 255, 255));
        jLabel17.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel17.setForeground(new java.awt.Color(255, 255, 255));
        jLabel17.setText("DATA NASC.");
        getContentPane().add(jLabel17);
        jLabel17.setBounds(450, 10, 80, 14);

        jb_salvar.setBackground(new java.awt.Color(255, 255, 255));
        jb_salvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/assistec_salvar.png"))); // NOI18N
        jb_salvar.setText("SALVAR");
        jb_salvar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(78, 78, 78)));
        jb_salvar.setBorderPainted(false);
        jb_salvar.setEnabled(false);
        jb_salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_salvarActionPerformed(evt);
            }
        });
        getContentPane().add(jb_salvar);
        jb_salvar.setBounds(770, 570, 100, 50);

        jb_editar.setBackground(new java.awt.Color(255, 255, 255));
        jb_editar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/assistec_editar.png"))); // NOI18N
        jb_editar.setText("EDITAR");
        jb_editar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(78, 78, 78)));
        jb_editar.setBorderPainted(false);
        jb_editar.setEnabled(false);
        jb_editar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_editarActionPerformed(evt);
            }
        });
        getContentPane().add(jb_editar);
        jb_editar.setBounds(870, 570, 100, 50);

        jb_excluir.setBackground(new java.awt.Color(255, 255, 255));
        jb_excluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/assistec_deletar.png"))); // NOI18N
        jb_excluir.setText("EXCLUIR");
        jb_excluir.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(78, 78, 78)));
        jb_excluir.setBorderPainted(false);
        jb_excluir.setEnabled(false);
        jb_excluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_excluirActionPerformed(evt);
            }
        });
        getContentPane().add(jb_excluir);
        jb_excluir.setBounds(970, 570, 100, 50);

        jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/assistec_lupa.png"))); // NOI18N
        getContentPane().add(jLabel16);
        jLabel16.setBounds(970, 200, 20, 30);

        jt_cliente.setAutoCreateRowSorter(true);
        jt_cliente.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jt_cliente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jt_cliente.setSelectionBackground(new java.awt.Color(0, 0, 0));
        jt_cliente.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jt_clienteMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jt_cliente);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(0, 240, 1280, 300);

        jLabel15.setBackground(new java.awt.Color(255, 255, 255));
        jLabel15.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel15.setForeground(new java.awt.Color(255, 255, 255));
        jLabel15.setText("PESQUISAR CLIENTE");
        getContentPane().add(jLabel15);
        jLabel15.setBounds(990, 180, 130, 14);

        tf_pesquisar.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        tf_pesquisar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        tf_pesquisar.setSelectionColor(new java.awt.Color(0, 0, 0));
        tf_pesquisar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tf_pesquisarKeyReleased(evt);
            }
        });
        getContentPane().add(tf_pesquisar);
        tf_pesquisar.setBounds(990, 200, 280, 30);

        tf_id.setEditable(false);
        tf_id.setBackground(new java.awt.Color(255, 255, 255));
        tf_id.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        tf_id.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        tf_id.setSelectionColor(new java.awt.Color(0, 0, 0));
        getContentPane().add(tf_id);
        tf_id.setBounds(1060, 130, 50, 30);

        jLabel14.setBackground(new java.awt.Color(255, 255, 255));
        jLabel14.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel14.setForeground(new java.awt.Color(255, 255, 255));
        jLabel14.setText("ID");
        getContentPane().add(jLabel14);
        jLabel14.setBounds(1060, 110, 30, 20);

        jLabel13.setForeground(new java.awt.Color(255, 255, 255));
        jLabel13.setText("AssisTec");
        getContentPane().add(jLabel13);
        jLabel13.setBounds(10, 550, 60, 14);

        jSeparator1.setForeground(new java.awt.Color(255, 255, 255));
        getContentPane().add(jSeparator1);
        jSeparator1.setBounds(70, 560, 1210, 10);

        jLabel12.setBackground(new java.awt.Color(255, 255, 255));
        jLabel12.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel12.setForeground(new java.awt.Color(255, 255, 255));
        jLabel12.setText("ESTADO");
        getContentPane().add(jLabel12);
        jLabel12.setBounds(10, 130, 60, 14);

        tf_numero.setEditable(false);
        tf_numero.setBackground(new java.awt.Color(255, 255, 255));
        tf_numero.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        tf_numero.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        tf_numero.setSelectionColor(new java.awt.Color(0, 0, 0));
        getContentPane().add(tf_numero);
        tf_numero.setBounds(10, 90, 70, 30);

        jLabel11.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel11.setForeground(new java.awt.Color(255, 255, 255));
        jLabel11.setText("CADASTRAR CLIENTE");
        getContentPane().add(jLabel11);
        jLabel11.setBounds(1130, 170, 140, 14);

        jb_fechar.setBackground(new java.awt.Color(255, 255, 255));
        jb_fechar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/assistec_fechar.png"))); // NOI18N
        jb_fechar.setText("FECHAR");
        jb_fechar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(78, 78, 78)));
        jb_fechar.setBorderPainted(false);
        jb_fechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_fecharActionPerformed(evt);
            }
        });
        getContentPane().add(jb_fechar);
        jb_fechar.setBounds(1170, 570, 100, 50);

        jb_limpar.setBackground(new java.awt.Color(255, 255, 255));
        jb_limpar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/assistec_limpar.png"))); // NOI18N
        jb_limpar.setText("LIMPAR");
        jb_limpar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(78, 78, 78)));
        jb_limpar.setBorderPainted(false);
        jb_limpar.setEnabled(false);
        jb_limpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_limparActionPerformed(evt);
            }
        });
        getContentPane().add(jb_limpar);
        jb_limpar.setBounds(1070, 570, 100, 50);

        jLabel10.setBackground(new java.awt.Color(255, 255, 255));
        jLabel10.setForeground(new java.awt.Color(78, 78, 78));
        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/assistec_cliente.jpg"))); // NOI18N
        jLabel10.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        getContentPane().add(jLabel10);
        jLabel10.setBounds(1120, 10, 150, 150);

        jf_cep.setEditable(false);
        jf_cep.setBackground(new java.awt.Color(255, 255, 255));
        jf_cep.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        try {
            jf_cep.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###-###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jf_cep.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jf_cep.setSelectionColor(new java.awt.Color(0, 0, 0));
        getContentPane().add(jf_cep);
        jf_cep.setBounds(610, 90, 110, 30);

        jLabel9.setBackground(new java.awt.Color(255, 255, 255));
        jLabel9.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel9.setForeground(new java.awt.Color(255, 255, 255));
        jLabel9.setText("CEP");
        getContentPane().add(jLabel9);
        jLabel9.setBounds(610, 70, 50, 14);

        tf_email.setEditable(false);
        tf_email.setBackground(new java.awt.Color(255, 255, 255));
        tf_email.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        tf_email.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        tf_email.setSelectionColor(new java.awt.Color(0, 0, 0));
        getContentPane().add(tf_email);
        tf_email.setBounds(330, 150, 220, 30);

        jLabel8.setBackground(new java.awt.Color(255, 255, 255));
        jLabel8.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(255, 255, 255));
        jLabel8.setText("EMAIL");
        getContentPane().add(jLabel8);
        jLabel8.setBounds(330, 130, 60, 14);

        tf_cidade.setEditable(false);
        tf_cidade.setBackground(new java.awt.Color(255, 255, 255));
        tf_cidade.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        tf_cidade.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        tf_cidade.setSelectionColor(new java.awt.Color(0, 0, 0));
        tf_cidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_cidadeActionPerformed(evt);
            }
        });
        getContentPane().add(tf_cidade);
        tf_cidade.setBounds(430, 90, 170, 30);

        jLabel7.setBackground(new java.awt.Color(255, 255, 255));
        jLabel7.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(255, 255, 255));
        jLabel7.setText("CIDADE");
        getContentPane().add(jLabel7);
        jLabel7.setBounds(430, 70, 60, 14);

        jLabel6.setBackground(new java.awt.Color(255, 255, 255));
        jLabel6.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(255, 255, 255));
        jLabel6.setText("Nº");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(10, 70, 60, 14);

        jLabel5.setBackground(new java.awt.Color(255, 255, 255));
        jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("TELEFONE");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(210, 130, 70, 14);

        tf_bairro.setEditable(false);
        tf_bairro.setBackground(new java.awt.Color(255, 255, 255));
        tf_bairro.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        tf_bairro.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        tf_bairro.setSelectionColor(new java.awt.Color(0, 0, 0));
        getContentPane().add(tf_bairro);
        tf_bairro.setBounds(260, 90, 160, 30);

        tf_endereco.setEditable(false);
        tf_endereco.setBackground(new java.awt.Color(255, 255, 255));
        tf_endereco.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        tf_endereco.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        tf_endereco.setSelectionColor(new java.awt.Color(0, 0, 0));
        getContentPane().add(tf_endereco);
        tf_endereco.setBounds(550, 30, 280, 30);

        tf_nome.setEditable(false);
        tf_nome.setBackground(new java.awt.Color(255, 255, 255));
        tf_nome.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        tf_nome.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        tf_nome.setSelectionColor(new java.awt.Color(0, 0, 0));
        getContentPane().add(tf_nome);
        tf_nome.setBounds(10, 30, 300, 30);

        jLabel4.setBackground(new java.awt.Color(255, 255, 255));
        jLabel4.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("BAIRRO");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(260, 70, 60, 14);

        jLabel3.setBackground(new java.awt.Color(255, 255, 255));
        jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("ENDEREÇO");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(550, 10, 80, 14);

        jLabel2.setBackground(new java.awt.Color(255, 255, 255));
        jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("NOME DO CLIENTE");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(10, 10, 120, 14);

        jLabel20.setBackground(new java.awt.Color(255, 255, 255));
        jLabel20.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel20.setForeground(new java.awt.Color(255, 255, 255));
        jLabel20.setText("RG");
        getContentPane().add(jLabel20);
        jLabel20.setBounds(560, 130, 110, 14);

        jLabel21.setBackground(new java.awt.Color(255, 255, 255));
        jLabel21.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel21.setForeground(new java.awt.Color(255, 255, 255));
        jLabel21.setText("CPF");
        getContentPane().add(jLabel21);
        jLabel21.setBounds(700, 130, 110, 14);

        jLabel22.setBackground(new java.awt.Color(255, 255, 255));
        jLabel22.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel22.setForeground(new java.awt.Color(255, 255, 255));
        jLabel22.setText("CNPJ");
        getContentPane().add(jLabel22);
        jLabel22.setBounds(840, 130, 110, 14);

        jf_rg.setEditable(false);
        jf_rg.setBackground(new java.awt.Color(255, 255, 255));
        jf_rg.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        try {
            jf_rg.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jf_rg.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jf_rg.setSelectionColor(new java.awt.Color(0, 0, 0));
        getContentPane().add(jf_rg);
        jf_rg.setBounds(560, 150, 130, 30);

        jf_cpf.setEditable(false);
        jf_cpf.setBackground(new java.awt.Color(255, 255, 255));
        jf_cpf.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        try {
            jf_cpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jf_cpf.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jf_cpf.setSelectionColor(new java.awt.Color(0, 0, 0));
        getContentPane().add(jf_cpf);
        jf_cpf.setBounds(700, 150, 130, 30);

        jf_cnpj.setEditable(false);
        jf_cnpj.setBackground(new java.awt.Color(255, 255, 255));
        jf_cnpj.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        try {
            jf_cnpj.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###/####-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jf_cnpj.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jf_cnpj.setSelectionColor(new java.awt.Color(0, 0, 0));
        getContentPane().add(jf_cnpj);
        jf_cnpj.setBounds(840, 150, 130, 30);

        jButton2.setBackground(new java.awt.Color(255, 255, 255));
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/assistec_novo.png"))); // NOI18N
        jButton2.setText("NOVO");
        jButton2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        jButton2.setBorderPainted(false);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2);
        jButton2.setBounds(10, 570, 100, 50);

        jButton1.setBackground(new java.awt.Color(255, 255, 255));
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/assistec_atualizar.png"))); // NOI18N
        jButton1.setText("ATUALIZAR");
        jButton1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
        jButton1.setBorderPainted(false);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(110, 570, 100, 50);

        jLabel23.setBackground(new java.awt.Color(255, 255, 255));
        jLabel23.setForeground(new java.awt.Color(255, 255, 255));
        jLabel23.setText("TABELA DE CLIENTES");
        getContentPane().add(jLabel23);
        jLabel23.setBounds(570, 540, 130, 20);

        jLabel1.setBackground(new java.awt.Color(255, 255, 255));
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/assistec_fundo2.png"))); // NOI18N
        getContentPane().add(jLabel1);
        jLabel1.setBounds(0, 0, 1280, 650);

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void tf_cidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_cidadeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_cidadeActionPerformed

    private void jb_limparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_limparActionPerformed
                Limpar();
    }//GEN-LAST:event_jb_limparActionPerformed

    private void jb_fecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_fecharActionPerformed

        dispose();

    }//GEN-LAST:event_jb_fecharActionPerformed

    private void jt_clienteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jt_clienteMouseClicked
        mostraItens();
        jb_editar.setEnabled(true);
        jb_limpar.setEnabled(true);
        jb_excluir.setEnabled(true);
        jb_salvar.setEnabled(false);
        
                tf_nome.setEditable(true);
                jf_data.setEditable(true);
                tf_endereco.setEditable(true);
                tf_numero.setEditable(true);
                tf_complemento.setEditable(true);
                tf_bairro.setEditable(true);
                tf_cidade.setEditable(true);
                jf_cep.setEditable(true);               
                jf_telefone.setEditable(true);
                tf_email.setEditable(true);
                jf_rg.setEditable(true);
                jf_cpf.setEditable(true); 
                jf_cnpj.setEditable(true); 
                cb_estado.setEnabled(true);
                cb_sexo.setEnabled(true);
                jb_salvar.setEnabled(false);
        
    }//GEN-LAST:event_jt_clienteMouseClicked

    private void tf_pesquisarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_pesquisarKeyReleased
        pesquisarClientes();
    }//GEN-LAST:event_tf_pesquisarKeyReleased

    private void jb_salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_salvarActionPerformed
        cadastrarClientes();
    }//GEN-LAST:event_jb_salvarActionPerformed

    private void jb_editarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_editarActionPerformed
        editarClientes();
    }//GEN-LAST:event_jb_editarActionPerformed

    private void jb_excluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_excluirActionPerformed
        deletarClientes();
    }//GEN-LAST:event_jb_excluirActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        Novo();
        jb_editar.setEnabled(false);
        jb_excluir.setEnabled(false);
        jb_limpar.setEnabled(true);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        listarClientes();
        jb_editar.setEnabled(false);
        jb_excluir.setEnabled(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Tela_CadCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Tela_CadCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Tela_CadCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Tela_CadCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new Tela_CadCliente().setVisible(true);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(Tela_CadCliente.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cb_estado;
    private javax.swing.JComboBox cb_sexo;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton jb_editar;
    private javax.swing.JButton jb_excluir;
    private javax.swing.JButton jb_fechar;
    private javax.swing.JButton jb_limpar;
    private javax.swing.JButton jb_salvar;
    private javax.swing.JFormattedTextField jf_cep;
    private javax.swing.JFormattedTextField jf_cnpj;
    private javax.swing.JFormattedTextField jf_cpf;
    private javax.swing.JFormattedTextField jf_data;
    private javax.swing.JFormattedTextField jf_rg;
    private javax.swing.JFormattedTextField jf_telefone;
    private javax.swing.JTable jt_cliente;
    private javax.swing.JTextField tf_bairro;
    private javax.swing.JTextField tf_cidade;
    private javax.swing.JTextField tf_complemento;
    private javax.swing.JTextField tf_email;
    private javax.swing.JTextField tf_endereco;
    private javax.swing.JTextField tf_id;
    private javax.swing.JTextField tf_nome;
    private javax.swing.JTextField tf_numero;
    private javax.swing.JTextField tf_pesquisar;
    // End of variables declaration//GEN-END:variables
}
